﻿namespace OboutInc.SlideMenu
{
    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Web.UI;
    using System.Web.UI.Design;

    [ToolboxItem(false)]
    public abstract class SlideMenuItem : Control, IPostBackEventHandler, INamingContainer
    {
        internal int _eventCount;
        internal int _itemType;
        public static readonly object EventClick = new object();

        public event ClickEventHandler Click
        {
            add
            {
                base.Events.AddHandler(EventClick, value);
                this._eventCount++;
            }
            remove
            {
                base.Events.RemoveHandler(EventClick, value);
            }
        }

        protected SlideMenuItem()
        {
        }

        protected override bool OnBubbleEvent(object sender, EventArgs e)
        {
            return true;
        }

        protected virtual void OnClick(EventArgs e)
        {
            ClickEventHandler handler = (ClickEventHandler) base.Events[EventClick];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public void RaisePostBackEvent(string eventArgument)
        {
            this.OnClick(EventArgs.Empty);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (this.InnerHtml != string.Empty)
            {
                writer.Write(this.InnerHtml);
            }
            base.Render(writer);
        }

        [Description("Text or any client side code to display."), Bindable(true), Category("Behavior"), DefaultValue("")]
        public string InnerHtml
        {
            get
            {
                string str = (string) this.ViewState["InnerHTML"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["InnerHTML"] = value;
            }
        }

        [DefaultValue(""), Description("Client side code to run when user clicks."), Bindable(true), Category("Behavior")]
        public string OnClientClick
        {
            get
            {
                string str = (string) this.ViewState["OnClientClick"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["OnClientClick"] = value;
            }
        }

        [DefaultValue(""), Editor(typeof(UrlEditor), typeof(UITypeEditor)), Description("URL to open when user clicks."), Bindable(true), Category("Behavior")]
        public string Url
        {
            get
            {
                string str = (string) this.ViewState["Url"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["Url"] = value;
            }
        }

        [Category("Behavior"), Bindable(true), Description("URL target frame name."), DefaultValue("")]
        public string UrlTarget
        {
            get
            {
                string str = (string) this.ViewState["UrlTarget"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["UrlTarget"] = value;
            }
        }

        [Description("Title for the URL."), Category("Behavior"), DefaultValue(""), Bindable(true)]
        public string UrlTitle
        {
            get
            {
                string str = (string) this.ViewState["UrlTitle"];
                if (str != null)
                {
                    return str;
                }
                return string.Empty;
            }
            set
            {
                this.ViewState["UrlTitle"] = value;
            }
        }
    }
}

